<template>
  <el-scrollbar class="scroller">
    <div class="scrollbar-flex-content">
      <div
        v-for="item in category"
        :key="item"
        @click="clickCategory(item.id)"
        class="scrollbar-demo-item"
      >
        <div></div>
        <div class="font-bold">{{ item.name }}</div>
      </div>
    </div>
  </el-scrollbar>
</template>
<script setup>
import { getCategory } from "@/api/category";
import { ref, defineEmits } from "vue";

const emit = defineEmits(["clickCategory"]);

const category = ref([]);
const initCategory = () => {
  getCategory().then((res) => {
    category.value = res.result;
  });
};
const clickCategory = (id) => {
  emit("clickCategory", id);
  console.log(id);
};
initCategory();
</script>

<style scoped>
.scroller {
  height: 80px;
}
.scrollbar-flex-content {
  display: flex;
  color: #000000;
  font-size: 12px;
}
.scrollbar-demo-item {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 100px;
  height: 50px;
  margin: 10px;
  text-align: center;
  border-radius: 4px;
  transition: all 0.6s;
}
.scrollbar-demo-item:hover {
  box-shadow: 0px 5px 5px rgba(0, 0, 0, 0.3);
}
</style>
